import pygame
from pytmx import TiledTileLayer, load_pygame, TiledObjectGroup

from Action.SpriteWelcome import WelcomeSprite
from Actor.japanese_fire_soldier import JapaneseFireSoldier

def step3_show_actor_by_class():
    """
    step3: 重构图片显示样例
    :return:
    """
    # 初始化pygame
    pygame.init()
    # 获取游戏时钟
    clock = pygame.time.Clock()
    # 创建游戏的窗口 640 * 236 根据要显示图片的大小设置
    screen = pygame.display.set_mode((1280, 780), 0, 32)
    # 加载图片文件
    background = pygame.image.load("../Resources/tmx/map2-1.png").convert()
    tiled_map_data = load_pygame("../Resources/tmx/map2.tmx")
    xiao_tie = None
    Jap_soldier = None
    for group in tiled_map_data.objectgroups:
        if isinstance(group, TiledObjectGroup):
            if group.name == '敌人':
                for obj in group:
                    if obj.name == "4":
                        xiao_tie = WelcomeSprite(obj.x, obj.y, "../Resources/images/welcome/%d-1.png", 9)


    while True:
        # 游戏循环
        for event in pygame.event.get():
            # 关闭事件，进行退出处理
            if event.type == pygame.QUIT:
                exit()
        # 绘制图片到显示窗口
        screen.blit(background, (0, 0))
        # 显示角色在（200，200）的位置
        # 通过时钟对象指定循环频率
        clock.tick(20)
        xiao_tie.draw(screen)
        # 调用flip方法更新显示,也可以使用update方法
        pygame.display.flip()



if __name__ == '__main__':
    """
    通过main函数调用step3_show_actor_by_class
    """
    step3_show_actor_by_class()
